(function ($) {
    $(document).ready(function () {

        //初始化
        var margin_and_padding_overview = 45;
        var other_extra = 30;
        var item_height = 100;
        $(".farmer-overview-item-div").each(function(){
            item_height = 100;
            var village_overview_div_class = $(this).attr('class');
            var  village_overview_div_class_array= village_overview_div_class.split(" ");
            var village_total_count = parseInt(village_overview_div_class_array[2]);

            if(village_total_count > 0 ){
                item_height = $($(this).find('.fieldset-content')[0]).height() +margin_and_padding_overview;

                switch(parseInt((village_total_count-1) / 2)){
                    case 0:
                        item_height +=other_extra;
                        break;
                    default :
                        item_height = item_height * 2 + other_extra;

                }
            }
            $(this).height(item_height);
        });

        //绑定事件
        jQuery('.farmer-datacount').click(function(){
            var top_parent = jQuery(this).parent().parent().parent();
            var  all_datacount= top_parent.attr('class');
            var  datecount= jQuery(this).attr('class');
            var  all_datacountarray= all_datacount.split(" ");
            var  datacountarray= datecount.split(" ");
            var  sumdata = parseInt(all_datacountarray[2]);
            var  need_data = parseInt(datacountarray[1]);
            var new_height ="";
            item_height = $(top_parent.find('.fieldset-content')[0]).height() +margin_and_padding_overview;
            if(need_data > sumdata ){
                need_data =sumdata;
            }
            if(need_data ==0){
                need_data = 1;
            }
            switch(parseInt((need_data-1) / 2)){
                case 0:
                    item_height += other_extra;
                    break;
                case 1 :
                    item_height = item_height * 2 + other_extra;
                    break;
                case 2 :
                    item_height = item_height * 3 + other_extra;
                    break;
                case 3 :
                    item_height = item_height * 4 + other_extra;
                    break;
                case 4 :
                    item_height = item_height * 5 + other_extra;
                    break;
                case 5 :
                    item_height = item_height * 6 + other_extra;
                    break;
                case 6 :
                    item_height = item_height * 7 + other_extra;
                    break;
                case 7 :
                    item_height = item_height * 8 + other_extra;
                    break;
                case 8 :
                    item_height = item_height * 9 + other_extra;
                    break;

                case 9 :
                    item_height = item_height * 10 + other_extra;
                    break;

            }
            $(top_parent).height(item_height);

        })

    })
})(jQuery);














